package gr.handmademarket.po.implementations;

import gr.handmademarket.po.interfaces.Category;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 * the category.
 */
public class ProductCategory 
implements Category, Serializable{
	
	/**
	 * serialVersionUID.
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * category code.
	 */
	private int code;
	
	/**
	 * category name.
	 */
	private String name;
	
	/**
	 * parent category.
	 */
	private Category parent;
	
	/**
	 * children sellers.
	 */
	private Set<Category> childrenSellers = new HashSet<Category>();
	
	/**
	 * children product categories.
	 */
	private Set<Category> childrenProductCategories = new HashSet<Category>();
	
	/**
	 * Gets the code.
	 *
	 * @return Returns the code
	 */
	public int getCode() {
		return code;
	}
	
	/**
	 * Assigns a new value to the code.
	 *
	 * @param code the code to set
	 */
	public void setCode(int code) {
		this.code = code;
	}
	
	/**
	 * @return name.
	 */
	public String getName() {
		return name;
	}

	/**
	 * sets the name.
	 * @param name the name
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return parent category.
	 */
	public Category getParent() {
		return parent;
	}

	/**
	 * sets the parent category.
	 * @param parent the parent category.
	 */
	public void setParent(Category parent) {
		this.parent = parent;
	}
	
	public boolean isLeaf(){
		return childrenProductCategories.size() == 0 && childrenSellers.size() == 0;
	}
	
	@Override
	public String toString() {
		return getName();
	}

	public boolean isRoot() {
		return parent == null;
	}

	public Set<Category> getChildren() {
		Set<Category> children = new HashSet<Category>();
		children.addAll(childrenProductCategories);
		children.addAll(childrenSellers);
		return children;
	}
	
	/**
	 * @return children sellers.
	 */
	public Set<Category> getChildrenSellers() {
		return childrenSellers;
	}

	/**
	 * @param childrenSellers
	 */
	public void setChildrenSellers(Set<Category> childrenSellers) {
		this.childrenSellers = childrenSellers;
	}

	/**
	 * @return children product categories.
	 */
	public Set<Category> getChildrenProductCategories() {
		return childrenProductCategories;
	}

	/**
	 * @param childrenProductCategories
	 */
	public void setChildrenProductCategories(Set<Category> childrenProductCategories) {
		this.childrenProductCategories = childrenProductCategories;
	}

}
